/**
 * Created by madi on 2018/9/4.
 */
import React from 'react';
import { Upload, message, Button, Icon } from 'antd';
import {host} from '../../utils/config';


const UPpdateImg = (getUrl)=>{

    const props = {
        name: 'file',
        action: `${host}/upload`,
        withCredentials:true,
        headers: {
            // "content-type": 'multipart/form-data',
        },
        data : {
            tag:getUrl.name,
        },
    };
    return <Upload {...props} fileList={getUrl.fileList} onChange={info =>{
        let fileList = info.fileList;
        //限制上传文件的数量,只显示最近上传的1个文件，旧文件将被新的文件替换。
        fileList = fileList.slice(-1);
        if(info.fileList[0]){
            fileList[0].name = info.fileList[0].originFileObj.name;
        }
        getUrl.getUrl(fileList);
        if (info.file.status === 'done') {
            message.success(`${info.file.name} 上传成功`);
        } else if (info.file.status === 'error') {
            message.error(`${info.file.name} 上传失败`);
        }
    }}>
        <Button style={{width: 300, marginBottom: 10, marginTop: -4}}>
            <Icon type="upload" /> 点击上传
        </Button>
    </Upload>;

};
export default UPpdateImg;
